package app.server.project.core.tcp;

import app.server.project.core.tcp.model.TcpReqModel;
import cn.hutool.json.JSONUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 解码器
 */
@Slf4j
public class JsonDecoder extends MessageToMessageDecoder<String> {

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, String msg, List<Object> list) throws Exception {
        var tcpModel = JSONUtil.toBean(msg, TcpReqModel.class);
        list.add(tcpModel);
    }
}
